import base64
import pickle
from django.http import JsonResponse
from django.shortcuts import render, redirect

# Create your views here.
from django.views import View
from django_redis import get_redis_connection

from contents.models import ContentCategory
from goods.models import GoodsChannelGroup, SKU
from goods.utils import get_categories


class IndexView(View):
    def get(self, request):

        data = get_categories()
        context = {
            'categories': data
        }

        # 获取首页广告
        contents = {}
        cat_all = ContentCategory.objects.all()
        for cat in cat_all:
            contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')

        return render(request, 'index.html', context=context)

def favicon(request):
    return redirect('/static/favicon.ico')